<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>JSONP解决跨域三</h1>
    <button id="btn">提交JSON请求</button>

    <script>
        //获取元素
        const oBtn = document.getElementById('btn')

        //定义一个函数接收数据
        function cd(data){
            console.log(data);
        }

        //绑定点击事件
        oBtn.onclick = function(){
            //点击添加script标签 利用script没有跨域的特性
            const oScript = document.createElement('script')
            //添加src的属性把数据放在地址是上
            oScript.src = 'http://127.0.0.1:4000/jsonAll?callback=cd'
            //添加到元素上
            document.body.appendChild(oScript)
        }
    </script>
</body>
</html>